package com.example.venue_reservation_service.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.venue_reservation_service.domain.Balance;
import com.example.venue_reservation_service.service.BalanceService;
import com.example.venue_reservation_service.mapper.BalanceMapper;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
* @author 31586
* @description 针对表【venue_balance】的数据库操作Service实现
* @createDate 2024-11-12 21:43:55
*/
@Service
public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, Balance>
    implements BalanceService{

    @Override
    public void returnMoney(Integer userId, Double money) {
        Balance balance = getOne(Wrappers.<Balance>lambdaQuery().eq(Balance::getUserId, userId));
        // 判空
        if (Optional.ofNullable(balance).isPresent()) {
            balance.setBalance(balance.getBalance() + money);
            updateById(balance);
        }
    }
}




